var t = getApp();

Page({
    data: {
        stop1: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/stop1.png",
        play1: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/play1.png",
        songStop: !1,
        selectedNum: null,
        sliderTime: 0,
        page: 1
    },
    onLoad: function(t) {
        this.getData(), this.init();
    },
    gotoDetail: function(t) {
        console.log(t.currentTarget.dataset.info, "跳转到商品详情的id"), console.log(t.currentTarget.dataset.type);
        var e = t.currentTarget.dataset.type, o = t.currentTarget.dataset.status;
        0 == e ? wx.showToast({
            title: o,
            icon: "none"
        }) : wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + t.currentTarget.dataset.info
        });
    },
    init: function() {
        var t = this, e = this;
        this.innerAudioContext = wx.createInnerAudioContext(), this.innerAudioContext.onPlay(function() {
            console.log("开始播放"), console.log(t.innerAudioContext.duration);
        }), this.innerAudioContext.onTimeUpdate(function() {
            setTimeout(function() {
                var o = t.innerAudioContext.currentTime / t.innerAudioContext.duration * 100, a = Math.floor(o);
                e.setData({
                    sliderTime: a
                }), Math.floor(t.innerAudioContext.duration) == Math.floor(t.innerAudioContext.currentTime) && t.setData({
                    songStop: !0
                });
            }, 1e3);
        }), this.innerAudioContext.onWaiting(function(t) {
            console.log("1111");
        }), this.innerAudioContext.onError(function(t) {
            console.log(t.errMsg), console.log(t.errCode);
        }), this.innerAudioContext.onSeeking(function(t) {
            console.log(t.errMsg);
        });
    },
    tapStatus: function(t) {
        console.log(t.currentTarget.id);
        var e = t.currentTarget.id;
        this.setData({
            src: this.data.voiceList[e].has_one_voice.curriculum[0].url,
            songStop: !1,
            selectedNum: e
        }), this.innerAudioContext.src = this.data.src, console.log(this.innerAudioContext.src), 
        this.innerAudioContext.play();
    },
    tapStatus_f: function(t) {
        console.log(t.currentTarget.id);
        var e = t.currentTarget.id;
        this.setData({
            songStop: !0,
            selectedNum: e
        }), this.innerAudioContext.pause();
    },
    onReady: function() {},
    onShow: function() {
        this.init();
    },
    onHide: function() {
        this.innerAudioContext.destroy(), this.setData({
            songStop: !0
        });
    },
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        console.log(this.data.current_page), console.log(this.data.last_page), this.data.current_page < this.data.last_page ? (wx.showLoading({
            title: "加载中",
            mask: !0
        }), this.setData({
            page: this.data.page + 1
        }), this.getNext(this.data.selected)) : wx.showToast({
            title: "没有更多",
            icon: "none"
        });
    },
    onShareAppMessage: function() {},
    getData: function() {
        var e = this, o = t.getNetAddresss("plugin.voice-goods.api.voice-goods.getVoiceList");
        t._getNetWork({
            url: o,
            data: {
                page: e.data.page
            },
            success: function(t) {
                var o = t.data;
                if (1 == o.result) {
                    for (var a = o.data.data, n = 0; n < a.length; n++) a[n].created_at = a[n].created_at.substring(0, 10);
                    e.setData({
                        voiceList: o.data.data,
                        current_page: o.data.current_page,
                        last_page: o.data.last_page
                    });
                }
                console.log(o.data.data);
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getNext: function() {
        var e = this, o = t.getNetAddresss("plugin.voice-goods.api.voice-goods.getVoiceList");
        t._getNetWork({
            url: o,
            data: {
                page: e.data.page
            },
            success: function(t) {
                var o = t.data;
                if (1 == o.result) {
                    if (o.data.current_page > o.data.last_page) return wx.hideLoading(), wx.showToast({
                        title: "没有更多",
                        icon: "none"
                    }), void e.setData({
                        current_page: o.data.current_page,
                        last_page: o.data.last_page
                    });
                    wx.hideLoading(), e.setData({
                        voiceList: o.data.data,
                        current_page: o.data.current_page,
                        last_page: o.data.last_page
                    });
                } else console.log(o.msg);
                console.log(o.data.data);
            },
            fail: function(t) {
                console.log(t);
            }
        });
    }
});